#pragma once

#include <string>
using namespace std;

#include "topdbs_common.hpp"
#include "topdbs_error.hpp"

namespace topdbs
{
	class topdbs_base_connection
		: public topdbs_error
	{
	protected:
		eDBSClient_t m_dbsClient;	
		std::string m_charset;
		uint16_t m_locktime;
	public:	
		topdbs_base_connection()
			: m_dbsClient(topdbs_unkown)
			, m_locktime(0)
		{
		}	
		//! A destructor.
		virtual ~topdbs_base_connection(){ };

		//! Returns the database clientType
		inline void setClientType(eDBSClient_t dbsClient) { m_dbsClient = dbsClient;};
		inline eDBSClient_t getClientType() { return m_dbsClient; };	
		inline void setClientCharset(const string& charset) { m_charset = charset; };
		inline string& getClientCharset(){ return m_charset; };
		inline void setLockwaitTime(uint16_t locktime) { m_locktime = locktime;};
		
		//! virtual function interface 
		//! Opens the connection to a data source.
		//! @param dbString  <host:port>@<database_name>
		virtual int  connect(
			eDBSClient_t dbsClientType,
			const string& dbString,   
			const string& user=string(),
			const string& pass=string(),
			void* pOption = NULL ) = 0;
		//! Returns the connection state for a particular connection object.	
		virtual bool isConnected() = 0;
		virtual int  reConnect()   = 0;
		//! Disconnects the connection from the database.
		virtual int  disConnect()  = 0;	
		//! Begin transactions.
		virtual int  begin() = 0;
		//! Commits transactions.
		virtual int  commit() = 0;
		//! Rollback transactions.
		virtual int  rollback() = 0;
		//! Returns transactions.
		virtual bool isTransaction() = 0;
		//! Sets the connection to be committed automatically.
		virtual int  autoCommit(bool on = true) = 0;
		//! Returns the native connection
		virtual void*  getConnection() = 0;
		//! Returns the current this
		virtual void* from_this() = 0;
		//! Sets the connection lock wait time
		virtual int lockwait() = 0;
	};
}